<?php
/**
 * Nadëb (Makú-Nadëb)
 *
 * @filesource 
 * @copyright  Copyright 2010 mateusweb.com.br
 * @license    Freeware
 * @package    Nadeb_Data_Grid
 * @subpackage Nadeb.Grid.Table
 * @version    1.0
 */

class Nadeb_Report_Table extends Nadeb_Report_Sql
{
	protected $prop;
	protected $gd;
	
	public function __construct($_params)
	{
		parent::__construct($_params);

		if( $this->get_totalPages() )
			$this->get_data();
		else
			return false;
	}
	
	public function __set($_obj,$_param)
	{
		$this->prop[$_obj] = $_param;
	}
	
	/*
	 * monta o tabela para a formação do grid
	 */
	public function create_table()
	{
		$this->get_variables();
		/*
		$_url  = $this->params;
		
		$url_query  = "/";
		$url_query .= $_url['module'] . "/";
		$url_query .= $_url['controller'] . "/";
		$url_query .= $_url['action'] . "/search/0/";
		
		$url_path  = "/";
		$url_path  .= $_url['module'] . "/";
		$url_path  .= $_url['controller'] . "/";
		$url_path  .= $_url['action'];
		
		unset($_url['module']);
		unset($_url['controller']);
		unset($_url['action']);
		if( isset($_url['search']) ) unset($_url['search']);
		
		#foreach( $_url as $key => $value  )
		#	$url_query .= $key . "/" . $value;
		
		foreach( $_url as $key => $value  )
			$url_path .= $key . "/" . $value;
			
		$this->gd = "";		
		if( isset($this->params[3]["search"]) && !isset($this->params[3]["allParams"]["ajax"]) )
		{
			$this->gd .= "<!-- SEARCH! -->\n\t<div id=\"dSearch\">\n";
		    $this->gd .= "\t\t\t\t<form id=\"fSearch\" method=\"post\" action=\"{$url_query}\">\n";
		    
		    foreach( $this->params[3]["search"] as $obj => $array)
		    {
			    $this->gd .= "\t\t\t\t\t\t\t<select name=\"$obj\" id=\"$obj\">\n";
			    foreach( $array as $label => $values )
			    	$this->gd .= "\t\t\t\t\t\t\t<option value=\"-\">$label</option>\n";
			    	$this->gd .= "\t\t\t\t\t\t\t<option value=\"-\">-</option>\n";
			    	foreach( $values as $key => $value )
			    		$this->gd .= "\t\t\t\t\t\t\t<option value=\"$key\">$value</option>\n";
			    $this->gd .= "\t\t\t\t\t\t\t</select>\n";
		    }
			$this->gd .= "\t\t\t\t\t\t\t<input type=\"submit\" class=\"bot_excluir\" value=\"Buscar\" />\n";
			$this->gd .= "\t\t\t\t</form>\n";
			$this->gd .= "\t</div>\n<!-- SEARCH! -->\n";
		}
		*/
		
		$url_path = "/{$this->params['module']}/{$this->params['controller']}/delete/";
		if( isset($this->params['rel']) ) $url_path .= "rel/" . $this->params['rel'] . "/";
		
		$this->gd .= "<!-- DATAGRID! -->\n\t<form id=\"fGrid\" method=\"post\" action=\"{$url_path}\">\n";
		$this->gd .= "\t\t<table summary=\"{$this->title}\">\n"; 
		
		if($this->title)
			$this->gd .= "	\t\t<caption>{$this->title}</caption>\n";

		$this->gd .= Nadeb_Report_Header::get_xhtml( $this->headerConfigs );
		$this->gd .= Nadeb_Report_Footer::get_xhtml( $this->footerConfigs );
		$this->gd .= Nadeb_Report_Body::get_xhtml  ( $this->bodyConfigs );
			
		$this->gd .= "\t\t</table>\n";
		$this->gd .= "\t</form>\n<!-- DATAGRID! -->\n";
	}
	
	public function get()
	{
		return $this->gd;
	}
}
